//
//  OAuthEngine.h
//  WeiboPad
//
//  Created by junmin liu on 10-10-5.
//  Copyright 2010 Openlab. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ShareKit.h"
#import "OAuthController.h"
#import "ASIHTTPRequestDelegate.h"

@protocol OAuthEngineDelegate <NSObject>
- (void)OAuthEngine:(OAuthEngine*)engine authrizedWithData: (NSString*)data;
- (void)OAuthEngine:(OAuthEngine *)engine willPresentOAuthController:(OAuthController*)controller;
- (void)OAuthEngine:(OAuthEngine *)engine failedWithError:(NSError*)error;
- (void)OAuthEngineCancel:(OAuthEngine *)engine;
@end

@class OAToken;
@class OAConsumer;
@class OAuth;

typedef enum {
    kOAuthStatusIdle,
    kOAuthStatusWaitforRequestToken,
    kOAuthStatusWaitforPin,
    kOAuthStatusWaitforAccessToken
} OAuthStatus;


@interface OAuthEngine : NSObject<OAuthControllerDelegate,ASIHTTPRequestDelegate> {
	id<OAuthEngineDelegate> _delegate;
	OAConsumer	*_consumer;
	OAToken		*_requestToken;
	OAToken		*_accessToken;
    OAuth       *_oAuth; 
    NSError     *_error;
    NSString    *_shareType;
    
    OAuthStatus _status;
    UIViewController *_baseViewController;
    OAuthController *_oAuthController;
}
@property(nonatomic,assign) id<OAuthEngineDelegate> delegate;
@property(nonatomic,retain) NSString* shareType;
@property(nonatomic, retain) OAConsumer* consumer;
@property (nonatomic, readwrite, retain)  NSString	*pin;
@property (nonatomic, retain) OAToken		*requestToken;
@property (nonatomic, retain) OAToken		*accessToken;
@property (nonatomic, retain) UIViewController *baseViewController;
@property(nonatomic,retain) NSError *error;

+ (OAuthEngine *)OAuthEngineForType:(NSString*)shareType delegate:(NSObject*)delegate;
- (OAuthEngine *) initOAuthWithDelegate: (NSObject *) delegate;
- (void) startAuthorize;
- (void) requestAccessToken;
- (void) requestPincode;
- (void) requestRequestToken;

@end

@interface QQWeiboOAuthEngine : OAuthEngine
@end
